import Vue from 'vue';
import Vuex from 'vuex';
import user from './modules/user';
import passCourceItem from './modules/passCourceItem.js';
import dictionary from './modules/dictionary';
import homePro from './modules/homePro';
import catalog from './modules/catalog';
import publicInterface from './modules/publicInterface';
Vue.use(Vuex);
const debug = process.env.NODE_ENV !== 'production';
/**
 * 获取传入模块内所有 方法名称
 * @param storeModule {{namespaced: string}}
 * @param types {Object}
 * @param moduleName {string}
 * @return {{}}
 */
function formatModuleTypes (storeModule = {}, types = {}, moduleName = '') {
  const { namespaced } = storeModule;
  return !namespaced
    ? types
    : Object.keys(types).reduce((result = {}, key) => {
        result[key] = `${moduleName}/${types[key]}`;
        return result;
      }, {});
}
// 字典模块异步方法
export const DIC_ACTION_TYPES = formatModuleTypes(dictionary, dictionary.actionTypes, 'dictionary');
export const HOME_ACTION_TYPES = formatModuleTypes(homePro, homePro.actionTypes, 'homePro');
export const CATALOG_ACTION_TYPES = formatModuleTypes(catalog, catalog.actionTypes, 'catalog');
// 字典模块同步方法
export const DIC_MUTATION_TYPES = formatModuleTypes(dictionary, dictionary.mutationTypes, 'dictionary');
export const HOME_MUTATION_TYPES = formatModuleTypes(homePro, homePro.mutationTypes, 'homePro');
// GETTES属性
export const DIC_GETTERS_TYPES = formatModuleTypes(dictionary, dictionary.gettersTypes, 'dictionary');
export const HOME_GETTERS_TYPES = formatModuleTypes(homePro, homePro.gettersTypes, 'homePro');
export default new Vuex.Store({
  modules: {
    dictionary,
    passCourceItem,
    user,
    homePro,
    catalog,
    publicInterface
  },
  strict: debug
});
